from datetime import datetime

from django.db import models
from django.contrib.auth.models import AbstractUser


# Create your models here.
class VerifyCode(models.Model):
    # 默认null=False 、 blank=False
    # null是针对数据库而言，而blank是针对表单而言的
    code = models.CharField('验证码', max_length=10)
    add_time = models.DateTimeField('添加时间', default=datetime.utcnow)
    email = models.EmailField('邮箱', default='', null=False, blank=False)

    class Meta:
        verbose_name = '验证码'
        verbose_name_plural = verbose_name

    def __str__(self):
        return '<Code:{}>'.format(self.code)


# 扩展原来的用户模型
class User(AbstractUser):
    # 继承原先的自带的用户模型
    choices = [('male', '男'),
               ('female', '女')]
    phone = models.CharField(verbose_name='电话', max_length=20)
    gender = models.CharField(verbose_name='性别', choices=choices, max_length=4)
    # code = models.CharField(verbose_name='验证码', max_length=10, default='')

    # 定义元数据
    class Meta:
        verbose_name = '用户'
        verbose_name_plural = verbose_name

    def __str__(self):
        return '<User:{}>'.format(self.username)
